package com.ba.base.api

import com.ba.base.model.vo.UserEntity
import com.ba.base.utils.SharedPreUtils
import qsos.core.lib.config.CoreConfig
import qsos.lib.base.base.BaseApplication

/**
 *
 * 认证数据
 */
object ApiAuth {

    val POST
        get() = if (CoreConfig.DEBUG) "/base-proxy" else "/base-proxy"

    enum class STATUS {
        NULL,
        LOGIN,
        AUTH
    }

    /**登录与认证状态*/
    var status: STATUS = STATUS.NULL

    var bearer: String = ""
        set(value) {
            field = "Bearer ${SharedPreUtils.getToken(BaseApplication.appContext)}"

        }

    var refreshToken: String = ""

    fun getBearerBase(): String {
        return bearer.replace("Bearer ", "")
    }

    const val basic: String = "Basic QmFzZVBsYXRmb3JtOjEyMzQ1Ng=="

    var userId: String = ""
    var deptId: Int = -1
    var phone: String = ""
    var pwd: String? = ""
    var userName: String? = ""

    var user: UserEntity? = null
        get() {
            if (field == null) {
                field = SharedPreUtils.getUserInfo(BaseApplication.appContext)
                status = when {
                    field?.isCertified == "T" -> {
                        STATUS.AUTH
                    }
                    field != null -> {
                        STATUS.LOGIN
                    }
                    else -> {
                        STATUS.NULL
                    }
                }
            }
            return field
        }
}